package com.one.group.admin.controller;

import com.one.group.admin.service.impl.SpBillServiceImpl;
import com.one.group.enums.ErrorCode;
import com.one.group.model.dto.BaseDeleteDto;
import com.one.group.model.dto.SpBillQueryDto;
import com.one.group.result.Result;
import com.one.group.utils.ResultUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/SpBill")
@Tag(name = "账单相关 接口")
public class SpBillController {
    @Autowired
    private SpBillServiceImpl spBillService;
    @PostMapping("/list")
    @Operation(summary = "查询账单")
    public Result list(@RequestBody SpBillQueryDto spBillQueryDto){
        return ResultUtil.success(spBillService.myQueryList(spBillQueryDto,null));
    }
    @PostMapping("/statusList0")
    @Operation(summary = "查询未缴账单")
    public Result statusList0(@RequestBody SpBillQueryDto spBillQueryDto){
        return ResultUtil.success(spBillService.myQueryList(spBillQueryDto,0));
    }
    @PostMapping("/statusList1")
    @Operation(summary = "查询已缴账单")
    public Result statusList1(@RequestBody SpBillQueryDto spBillQueryDto){
        return ResultUtil.success(spBillService.myQueryList(spBillQueryDto,1));
    }
    @PostMapping("/sendNotification")
    @Operation(summary = "发送通知")
    public Result sendNotification(@RequestBody BaseDeleteDto baseDeleteDto){
        if(spBillService.sendNotification(baseDeleteDto)){
            return ResultUtil.success();
        }
        return ResultUtil.error(ErrorCode.OPERATION_ERROR);
    }
    @DeleteMapping("/delete")
    @Operation(summary = "删除账单")
    public Result delete(@RequestBody BaseDeleteDto baseDeleteDto){
        if(spBillService.removeByIds(baseDeleteDto.getIds())){
            return ResultUtil.success();
        }
        return ResultUtil.error(ErrorCode.OPERATION_ERROR);
    }
    @GetMapping("/paiedTotalAmount")
    @Operation(summary = "查询已缴总金额")
    public Result paiedTotalAmount(){
        return ResultUtil.success(spBillService.paiedTotalAmount());
    }
}
